/* 
 * File:   Application.hpp
 * Author: bd
 *
 * Created on March 26, 2011, 1:56 PM
 */

#ifndef APPLICATION_HPP
#define	APPLICATION_HPP
#include <boost/thread.hpp>

#include "Activity.hpp"
#include "ActivityManager.hpp"
#include "Configuration.hpp"
#include "Pool.hpp"

template<typename T>
class Monitor {
public:

    T get() {
        lock_guard lock(mutex_);
        return obj_;
    }

    void set(const T& obj) {
        lock_guard lock(mutex_);
        obj_ = obj;
    }
private:
    typedef boost::lock_guard<boost::mutex> lock_guard;
    T obj_;
    boost::mutex mutex_;
};

/*
 *  Starting point of the application.
 * Responsibilites:
 *      - Read configuration
 *      - Create activities
 *      - Start activities
 *
 */


class Application {
public:
    Application();
    Application(const Application& orig);
    virtual ~Application();

    //Member functions
    void main();
    void init();
    void loadConfig();
    void start();
    void stop();

    static Monitor<bool> monitor;

protected:
    void createActivities();
    void loadtestdata();
private:
    ActivityManager actmng_;
    std::vector<boost::shared_ptr<boost::thread> > threads_;
    Configuration config_;
    Pool<ShortMsgItem> pool_;
    static const std::string CONFIG_FILENAME;
};

#endif	/* APPLICATION_HPP */

